package com.shengruan.admin.jdbc;

import com.shengruan.admin.vo.SubscriptionEmail;
import com.shengruan.framework.jdbc.BaseJdbc;
import com.shengruan.framework.jdbc.BeanHandler;
import com.shengruan.framework.jdbc.BeanListHandler;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @author <a href="mailto:zhdqCN@gmail.com">DaQing Zhou</a>
 * @version 1.0
 * @CreationTime: 12-7-3 上午12:08
 * @Description: To change this template use File | Settings | File Templates.
 */
public class SubscriptionEmailJdbc extends BaseJdbc {


    public void save(SubscriptionEmail subscriptionEmail)
	{
		Connection conn = this.getConnection();
		String sql = "insert into subscription_email (email,createTime)values(?,?)";
		try {
			this.execute(conn, sql, subscriptionEmail.getEmail(), subscriptionEmail.getCreateTime());
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			this.close(conn);
		}
	}

     public SubscriptionEmail getByEmail(String email) {
        Connection conn = this.getConnection();
        SubscriptionEmail subscriptionEmail = null;
        Object[] pram = {email};
        try {
            subscriptionEmail = this.query(conn, "select * from subscription_email where email = ?", new BeanHandler<SubscriptionEmail>(SubscriptionEmail.class), pram);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            this.close(conn);
        }
        return subscriptionEmail;
    }



    public  List<SubscriptionEmail> getList()
	{
		List<SubscriptionEmail> subscriptionEmailList = new ArrayList<SubscriptionEmail>();
		Connection conn = this.getConnection();
		String sql = "select * from  subscription_email order by createTime desc";
		try {
			subscriptionEmailList = this.query(conn, sql,new BeanListHandler<SubscriptionEmail>(SubscriptionEmail.class));
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			this.close(conn);
		}
		return subscriptionEmailList;
	}
}
